package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.result_entity.fileInfo;
import com.ruoyi.system.mapper.FileInfoServiceMapper;
import com.ruoyi.system.service.FileInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class FileInfoServiceImpl extends ServiceImpl<FileInfoServiceMapper, fileInfo> implements FileInfoService {


    @Resource
    private FileInfoServiceMapper fileInfoServiceMapper;

    @Override
    public fileInfo getByFileHash(String fileHash) {
        // 使用baseMapper调用自定义方法
        return baseMapper.selectByFileHash(fileHash);
    }

    // 保存文件信息
    @Override
    public boolean savefileInfo(fileInfo fileInfo) {
        return this.save(fileInfo);
    }

    @Override
    public boolean deleteByFileHash(String fileHash) {
        return this.lambdaUpdate().eq(fileInfo::getFileHash, fileHash).remove();
    }

    // 实现根据文件路径查询文件信息
    @Override
    public fileInfo getByFilePath(String filePath) {
        // 直接调用Mapper中手动定义的selectByFilePath方法
        fileInfo fileInfo = fileInfoServiceMapper.selectByFilePath(filePath);
        return fileInfo;
    }
}
